<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
    <title>测试流式</title>
</head>
<body>
	<h1>测试流式</h1>
    <div id="output"></div>
    <br/>
    <button onclick="handleClick()">发送</button>
</body>
<script>
async function fetchStream() {
  const output = document.getElementById('output');
  const response = await fetch('http://10.10.22.5:8889/gbi/Push/liushi');

  // 创建流读取器
  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  // 持续读取数据
  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    
    // 解码并显示数据块
    const chunk = decoder.decode(value, { stream: true });
    console.log(chunk, 'chunk')
    output.innerHTML += chunk;  // 或使用 textContent 更安全
  }
}

function handleClick() {
    fetchStream();
}
// 启动请求
// fetchStream();
</script>
</html>